<!--社区列表-->
<template>
    <div>
            <el-row :gutter="10">
               <el-col v-if="localshowCId" :span='6'>
                  <el-select v-model="c_id" placeholder="所属社区" clearable>
                      <el-option
                              v-for="item in allcommunitylist"
                              :key="item.value"
                              :label="item.label"
                              :value="item.value">
                      </el-option>
                  </el-select>
               </el-col>
               <el-col :span='6'>
                  <el-input v-model="s_name">
                    <template slot="prepend">学校名称</template>
                  </el-input>
               </el-col>
               <el-col :span='6'>
                  <el-select v-model="type" placeholder="学校类型" clearable>
                      <el-option
                              v-for="item in schooltype"
                              :key="item.value"
                              :label="item.label"
                              :value="item.value">
                      </el-option>
                  </el-select>
               </el-col>
            </el-row>
            <el-row class="yx_el_row">
                <el-col>
                    <el-button type="success" plain @click="search">筛选</el-button>
                    <el-button type="primary" plain @click="edit(-1,1)">添加</el-button>
                </el-col>
            </el-row>
            <el-table class="yx_table" border :data="schoollist">
                <el-table-column prop="index" label="序号" width="50">
                </el-table-column>
                <el-table-column prop="c_name" label="所属社区" width="100">
                </el-table-column>
                <el-table-column prop="g_name" label="所属网格" width="100">
                </el-table-column>
                <el-table-column prop="s_name" label="学校名称" width="100">
                </el-table-column>
                <el-table-column prop="type" label="学校类型" width="100">
                </el-table-column>
                <el-table-column prop="teacher_num" label="教师人数" width="100">
                </el-table-column>
                <el-table-column prop="student_num" label="学生人数" width="100">
                </el-table-column>
                <el-table-column prop="class_num" label="班级数额" width="100">
                </el-table-column>
                <el-table-column prop="master" label="主要负责人" width="100">
                </el-table-column>
                <el-table-column prop="master_phone" label="负责人电话" width="100">
                </el-table-column>
                <el-table-column prop="address" label="详细地址" width="180">
                </el-table-column>
                <el-table-column  label="操作">
                    <template slot-scope="scope">
                        <el-tooltip class="item" effect="dark" content="编辑" placement="bottom-start">
                            <el-button type="primary" icon="el-icon-edit" @click="edit(scope.row.id,2)" circle></el-button>
                        </el-tooltip>
                        <el-tooltip class="item" effect="dark" content="查看" placement="bottom-start">
                            <el-button type="info" icon="el-icon-notebook-1" @click="edit(scope.row.id,0)" circle></el-button>
                        </el-tooltip>
                        <el-tooltip class="item" effect="dark" content="删除" placement="bottom-start">
                            <el-button type="warning" icon="el-icon-delete" @click="del(scope.row.id)" circle></el-button>
                        </el-tooltip>
                    </template>
                </el-table-column>
            </el-table>
            <Pagination :total_count="total_count" :getList="getList"></Pagination>
    </div>
</template>

<script>
    import Pagination from '@/components/Pagination.vue';
    import { getSchoolList,delSchool } from '@/api/school.js';
    import { getAllCommunityList } from '@/api/community.js';
    export default {
        name: 'SchoolList',
        inject:['basic_data_reload'],
        components:{ Pagination },
        data() {
            return {
                schoollist:[],
                total_count:0,
                schooltype:this.$store.state.allschooltype,
                s_name:'',
                type:'',
                c_id:'',
                localshowCId:this.$store.getters.getLoginIsGrid==0?true:false,
                allcommunitylist:[]
            }
        },
        methods: {
            getList(current_page,page_size){
                var send_data={
                    api_token:this.$store.getters.getSessionId,
                    c_id:this.c_id==''?-1:this.c_id,
                    g_id:this.$store.getters.getCurrentGId,
                    s_name:this.s_name,
                    type:this.type,
                    current_page:current_page,
                    page_size:page_size
                }
                let that=this;
                getSchoolList(send_data).then(function(response){
                   if(response.data.code==1){
                     that.schoollist=response.data.list;
                     that.total_count=response.data.total_count;
                   }
                })
            },
            search(){
                this.getList(1,this.$store.state.default_page_size);
            },
            edit(id,edit_type){
                this.$router.push({
                    name:'schooledit',
                    params:{id:id,edit_type:edit_type}
                });
            },
            del(id){
                let that=this;
                //弹框提示
                this.$confirm('确认删除, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then((e) => {
                    var send_data={
                        api_token : that.$store.getters.getSessionId,
                        id:id
                    };
                    delSchool(send_data).then(function(response){
                        let type=response.data.code==1?'success':'error';
                        let msg=response.data.code==1?'删除成功':'删除失败'
                        that.$message({
                            message:msg,
                            duration:1200,
                            type:type,
                            onClose:function(e){
                                that.basic_data_reload();
                            }
                        });
                    })
                })
            }
        },
        created() {
            let send_data={
               api_token:this.$store.getters.getSessionId
            };
            let that=this;
            getAllCommunityList(send_data).then(function(response){
                that.allcommunitylist=response.data.list;
            })
            this.getList(1,that.$store.state.default_page_size);
        },
        computed:{
            showCId(){
                return this.$store.getters.getShowCId;
            }
        },
        watch:{
            '$route'(to,from){
                this.$store.commit('setCurrentGId',to.query.g_id);
                this.getList(1,this.$store.state.default_page_size);
            },
            showCId(val){
                this.localshowCId=val;
            }
        }
    }
</script>

<style>
     @import url('../../assets/css/table.css');
</style>
